package wjh.blog.pojo;

import java.util.Date;
import java.util.List;

import wjh.blog.exception.MsgException;
import wjh.blog.util.WebTool;

public class Blog {

	private Integer id;
	private BlogType type; //博客类别
	private User user; //用户
	
	private String title;//博客标题
	private String content; //博客内容
	private String remark;//简单摘要
	private Date publishTime;//发布时间
	private Integer good; //好评
	private Integer isShow; //显示
	private Integer readNum; //阅读数量
	
	private List<BlogComment> comments; //评论
	
	
	
	public String getRemark() {
		return remark;
	}
	public void setRemark(String remark) {
		this.remark = remark;
	}
	public BlogType getType() {
		return type;
	}
	public void setType(BlogType type) {
		this.type = type;
	}
	public String getTitle() {
		return title;
	}
	public void setTitle(String title) {
		this.title = title;
	}
	
	public Integer getId() {
		return id;
	}
	public void setId(Integer id) {
		this.id = id;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public Date getPublishTime() {
		return publishTime;
	}
	public void setPublishTime(Date publishTime) {
		this.publishTime = publishTime;
	}
	public Integer getGood() {
		return good;
	}
	public void setGood(Integer good) {
		this.good = good;
	}
	public Integer getIsShow() {
		return isShow;
	}
	public void setIsShow(Integer isShow) {
		this.isShow = isShow;
	}
	public Integer getReadNum() {
		return readNum;
	}
	public void setReadNum(Integer readNum) {
		this.readNum = readNum;
	}
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	public List<BlogComment> getComments() {
		return comments;
	}
	public void setComments(List<BlogComment> comments) {
		this.comments = comments;
	}

	public void check() throws MsgException {
		
		if(WebTool.checkLen(title,5,15)){
			throw new MsgException("标题长度错误");
		}
		
		if(WebTool.checkLen(content, 100,2500)){
			throw new MsgException("内容长度错误");
		}
		
		if(WebTool.checkZh(title)){
			throw new MsgException("有非法字符");
		}
		
		if(WebTool.checkJsOrMeta(content)){
			throw new MsgException("有脚本");
		}
		title = title.trim();
		content = content.trim();
		remark = content.substring(0, 100);
	}
	
	public void clear(){
		title=null;
		content=null;
		type=null;
	}
	
	
	
	
}
